<template>
	<view>
		<view class="box" v-html='data'></view>
		<view class="footer">
			<view class="van-row between">
				<view class="van-col">
					<text class="left">上进辅导礼包
						<text style="font-size: 13px; font-weight: 600; color: rgb(240, 110, 108);">¥</text>
						<text
							style="font-weight: 600; font-size: 16px; color: rgb(240, 110, 108);">{{speInfo.read_price_text}}</text>
					</text>
				</view>
				<view class="van-col" @click="orderAdd">
					<view class="right"><button class="settle">立即购买</button></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				speInfo: {
					read_price_text: ''
				},
				data: '<img src="https://zm.yzou.cn/static/images/444be9dbaff6a375897f..png" class="package-img">'
			}
		},
		onShow() {
			const {
				sVal
			} = this.$core.getCache("read_info")
			this.speInfo = sVal
		},
		methods: {
			orderAdd() {
				const info = this.$core.getCache('read_info')
				const args = {
					"enrollment_id": info.eVal.id, // 报读类型
					"grade_id": info.gVal.id, // 年级
					"read_level_id": info.lVal.id, // 层次
					"college_id": info.iVal.id, // 学院
					"major_id": info.sVal.id, // 专业
					"exam_area_id": info.qVal.id // 考区
				}
				console.log('下单请求参数',args);
				this.$core.post({
					url: 'god/readorder/add',
					data: args,
					success: (res) => {
						const { statusCode } = res;
						if (statusCode !== 200) {
							uni.showToast({ title: res.msg, icon: 'none' });
							console.error("下单-网络错误" + res.msg);
							return false;
						}
						const { code, data, msg } = res.data;
						if (code !== 1) {
							uni.showToast({ title: '下单报读失败，请重试！', icon: 'none' });
							console.error("下单-接口错误" + msg);
							return false;
						}
						const { order_id, order_no, pay_price } = data;
						// 跳转到支付
						const url = '/pages/pay/tuition?order_id=' + order_id + "&order_no=" + order_no +
							"&pay_price=" + pay_price;
						uni.navigateTo({ url })
					}
				});
			},
			navTo(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.box {
		width: 100%;
	}

	::v-deep [src] {
		width: 100%;
	}

	.footer {
		background: #fff;
		bottom: 0;
		left: 0;
		height: 120rpx;
		position: fixed;
		width: 100%;
		border-top: 1px solid #eee;

		.van-row {
			height: 100%;
			align-items: center;
		}

		.left {
			margin-left: 20rpx;
		}

		button {
			background: linear-gradient(135deg, #f09190, #f07877 66%, #f06e6c);
			border-radius: 40rpx;
			color: #fff;
			font-size: 32rpx;
			line-height: 80rpx;
			height: 80rpx;
			width: 50vw;
			margin: 0 20rpx;
		}
	}
</style>